<?php 

// +----------------------------------------------------------------------
// | Copyright (c) 2015-2020.
// +----------------------------------------------------------------------
// | Describe: 支付结果处理类
// +----------------------------------------------------------------------
// | Author: woniu
// +----------------------------------------------------------------------

class payResult{
	/** 
	* 异步支付结果回调 ，处理业务逻辑
	* 
	* @access public
	* @name  
	* @param mixed  参数一的说明 
	* @return array 
	*/  
	static function payNotify($params){
		global $_W;
		if($params['result'] == 'success' && $params['from'] == 'notify') {
			$records = pdo_get('fx_activity_records', array('orderno' => $params['tid'], 'uniacid' => $params['uniacid']));
			$activity = model_activity::getSingleActivity($records['activityid'], '*');
			$_W['oauth']['uniacid'] = $params['user'] != $records['openid'] ? '':$_W['uniacid'];
			$_W['uniacid'] = $params['uniacid'];
			if(!empty($records)) {
				if(!empty($params['tag'])) {
					$params['tag'] = iunserializer($params['tag']);
					//Array ( [transaction_id] => 4001602001201611230627952393) [is_usecard] => 0 [card_type] => 0 [card_fee] => 0.10 [card_id] => 0)
					if($params['is_usecard']==1){
						$fee = $params['card_fee'];
						$data['is_usecard'] = 1;
					}else{
						$fee = $params['fee'];
					}
				}else{
					fx_message ('抱歉，请正确支付您的订单！', '', 'error');
				}
				$data = array(
					'paytype' => $params['type'],
					'status' => 1,
					'paytime' => date('Y-m-d H:i:s',TIMESTAMP),
					'transid' => $params['tag']['transaction_id'],
					'uniontid' => $params['uniontid'],
					'payprice' => $params['fee']
				);
				if(!empty($activity['merchantid'])){
					model_merchant::updateAmount($fee, $activity['merchantid'],$records['id'],1,'订单支付成功');  //主办方进账
					pdo_insert("fx_merchant_money_record",array('merchantid'=>$activity['merchantid'],'uniacid'=>$_W['uniacid'],'money'=>$records['price'],'recordsid'=>$records['id'],'createtime'=>TIMESTAMP,'type'=>1,'detail'=>'支付成功<br>订单号：' . $records['orderno']));
				}
				//$listNum = pdo_fetchall("SELECT hexiaoma as num FROM " . tablename ('fx_activity_records') . " WHERE activityid = ".$activity['id']);
				//$data['hexiaoma'] = createNumber($listNum);
				$data['hexiaoma'] = createRandomNumber(8);
				pdo_update('fx_activity_records', $data, array('orderno' => $params['tid'], 'uniacid' => $params['uniacid']));
				//生成二维码
				createQrcode::creategroupQrcode($params['tid']);
				message::join_success($records['openid'], $activity, $records['id'], app_url('records/records/list'));// 报名成功通知
				if($activity['smsswitch']){//发送短信
					$smsparams=array(
						'product' => $_W['_config']['sname'],
						'item'    => $activity['title'],
						'name'    => $records['realname'],
						'timestr' => date('m月d日 H:i',strtotime($activity['starttime'])),
						'idcode'  => $data['hexiaoma']
					);
					sendSMS($records['mobile'],$smsparams,$activity['smsnotify'],$_W['_config']['sms_type']);
				}
				if ($_W['_config']['admin_notice']){//管理员通知
					if ($activity['merchantid'])
					$merchant = model_merchant::getSingleMerchant($activity['merchantid'], '*');//读取主办方
					$openids = unserialize($activity['openids']);
					$openids = !empty($openids) ? $openids : unserialize($merchant['messageopenid']);
					$openids = !empty($openids) ? $openids : $_W['_config']['openids'];
					if (!empty($openids)){
						foreach($openids as $key=> $value){
							message::admin_notice($value, $activity, $records['id'], '');
						}
					}
				}
			}
		}
	}
	/** 
	* 函数的含义说明 
	* 
	* @access public
	* @name 方法名称 
	* @param mixed  参数一的说明 
	* @return array 
	*/  
	static function payReturn($params){
		global $_W;

	}
	/** 
	* 函数的含义说明 
	* 
	* @access public
	* @name 方法名称 
	* @param mixed  参数一的说明 
	* @return array 
	*/  
	static function getPayData($params,$order_out,$goodsInfo){
	 	global $_W;
	
	}
}



?>